package com.cn.web.servlet;

import com.cn.service.BrandService;
import com.cn.service.BrandServiceImpl;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;

@WebServlet("/deleteByIdServlet")
public class DeleteServlet extends HttpServlet {
    BrandService brandService = new BrandServiceImpl();
    @Override
    protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        System.out.println("Enter deleteByIdServlet");
        //获取brandId
        String brandId = req.getParameter("brandId");
        int id = Integer.parseInt(brandId);
        int i = brandService.deleteById(id);
        if (i>0){
            resp.getWriter().write("success");
        }else{
            resp.getWriter().write("failure");
        }
    }

    @Override
    protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        this.doGet(req, resp);
    }
}
